package top.system.dept.utils;

import top.system.dept.pojo.SysResp;

/**
 * @author: Amosen
 * @time: 2021-5-16
 */

public class RespUtil {

	private static final Integer DEFAULT_SUCCESS_CODE = 200;

	private static final String DEFAULT_SUCCESS_MSG = "request: ok";

	private static final Integer DEFAULT_FAIL_CODE = 500;

	private static final String DEFAULT_FAIL_MSG = "request: fail";

	private static final Integer ILLEGAL_PARAM_CODE = 501;

	private static final String ILLEGAL_PARAM_MSG = "Illegal parameter";

	private static final Integer NO_LOGIN_CODE = 502;

	private static final String NO_LOGIN_MSG = "You have not login yet";

	private static final Integer UNIQUE_INVOICE_ID_ERROR_CODE = 503;

	private static final String UNIQUE_INVOICE_ID_ERROR_MSG = "You are trying to upload an existed invoice";

	private static final Integer LOW_AUTH_ERROR_CODE = 504;

	private static final String LOW_AUTH_ERROR_MSG = "You have not enough authority to do this";

	private static final Integer ACCOUNT_CONFLICT_ERROR_CODE = 505;

	private static final String ACCOUNT_CONFLICT_ERROR_MSG = "The account has been existed";

	public static SysResp success() {
		return new SysResp(DEFAULT_SUCCESS_CODE, DEFAULT_SUCCESS_MSG);
	}

	public static SysResp fail() {
		return new SysResp(DEFAULT_FAIL_CODE, DEFAULT_FAIL_MSG);
	}

	public static SysResp successData(String key, Object value) {
		SysResp resp = new SysResp(DEFAULT_SUCCESS_CODE, DEFAULT_SUCCESS_MSG);
		resp.getData().put(key, value);
		return resp;
	}

	public static SysResp failData(String key, Object value) {
		SysResp resp = new SysResp(DEFAULT_FAIL_CODE, DEFAULT_FAIL_MSG);
		resp.getData().put(key, value);
		return resp;
	}

	public static SysResp illegalParam() {
		return new SysResp(ILLEGAL_PARAM_CODE, ILLEGAL_PARAM_MSG);
	}

	public static SysResp noLogin() {
		return new SysResp(NO_LOGIN_CODE, NO_LOGIN_MSG);
	}

	public static SysResp uniqueInvoiceID() {
		return new SysResp(UNIQUE_INVOICE_ID_ERROR_CODE, UNIQUE_INVOICE_ID_ERROR_MSG);
	}

	public static SysResp lowAuth() {
		return new SysResp(LOW_AUTH_ERROR_CODE, LOW_AUTH_ERROR_MSG);
	}

	public static SysResp accountConflict() {
		return new SysResp(ACCOUNT_CONFLICT_ERROR_CODE, ACCOUNT_CONFLICT_ERROR_MSG);
	}

}
